# -*- coding: utf-8 -*-
# @Time : 2021/9/17 15:44
# @Author : WANGCHENYI
# @Email : wcy@gmail.com
# @File : MRYX-ST-TJSP-01.py
# @Project : mryx_test
"""到推荐商品界面点击商品，查看相似商品"""
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy as By
from time import sleep
from appium.webdriver.common.touch_action import TouchAction

desired_capabilities={
    "platformName":"Android",
    "deviceName":"127.0.0.1:62001",
    "platformVersion":"7.1.2",
    "appPackage":" cn.missfresh.application",
    "appActivity":"cn.missfresh.module.main.view.MainActivity",
    "noReset":True
}
driver=webdriver.Remote("http://localhost:4723/wd/hub",desired_capabilities)
#向上滑动
# size=driver.get_window_size()
# sleep(2)
# height=size.get("height")
# width=size.get("width")
# start_y=height*0.9
# end_y=height*0.5
# start_x=end_x=width*0.5
# driver.swipe(start_x,start_y,end_x,end_y)
# sleep(3)
# driver.swipe(start_x,start_y,end_x,end_y)
# sleep(3)
# driver.swipe(start_x,start_y,end_x,end_y)
start=driver.find_element(By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout/androidx.viewpager.widget.ViewPager/android.widget.ImageView')
end=driver.find_element(By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.widget.ImageView')
#下拉刷新
driver.scroll(start,end)
sleep(3)
#向上滚动
driver.scroll(end,start)
#选择商品
sleep(3)
driver.tap([(231,702)],5000)
#点击相似
sleep(2)
similar_locator=(By.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/androidx.recyclerview.widget.RecyclerView/android.widget.RelativeLayout[2]/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView')
driver.find_element(*similar_locator).click()
sleep(4)
driver.quit(4)
